package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.BalancePopItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserBindCardRes;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/9 16:13
 * description:
 */
public class BalancePopRvAdapter extends RecyclerView.Adapter<BalancePopRvAdapter.PopHolder> {

    private Context mContext;
    private TextView popTv;
    private ArrayList<String> itemViewData;
    public PopItemInterface popItemInterface;
    private TextView nickTv;
    private List<QueryUserBindCardRes.UserCardExBean> cardName;
    private TextView nickName;
    private TextView mCardName;

    public BalancePopRvAdapter(Context context) {
        mContext = context;
    }

    public void popItemOnclick(PopItemInterface popItemInterface) {
        this.popItemInterface = popItemInterface;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.balance_pop_item;
    }

    @Override
    public PopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return PopHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(PopHolder holder, int position) {
        loadItemView(position, holder.binding);
    }

    private void loadItemView(final int position, BalancePopItemBinding binding) {
        if (cardName != null) {
            QueryUserBindCardRes.UserCardExBean userCardExBean = cardName.get(position);

            if (userCardExBean != null) {
                String bindCardNo = userCardExBean.getBindCardNo();
                String cardNickName = userCardExBean.getCardNickName();
                binding.banPopItemNick.setText(cardNickName);
                binding.banPopItemTv.setText(bindCardNo);

            }
        }
        binding.banPopItemTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String bindCardNo = cardName.get(position).getBindCardNo();
//                Toast.makeText(mContext, "wodhidianji" + position, Toast.LENGTH_SHORT).show();
                    popItemInterface.onClick(v,bindCardNo);

            }
        });
    }

    @Override
    public int getItemCount() {
        return null == cardName ? 0 : cardName.size();
    }


    public void setCardName(List<QueryUserBindCardRes.UserCardExBean> cardName) {
        this.cardName = cardName;
    }

    public static class PopHolder extends RecyclerView.ViewHolder {
        private BalancePopItemBinding binding;

        public static PopHolder creat(ViewGroup parent) {
            BalancePopItemBinding binding = BalancePopItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new PopHolder(binding);
        }

        public PopHolder(BalancePopItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }


    public interface PopItemInterface {
        public void onClick(View view,String cardNo);
    }


}
